﻿set(PROJECT_NAME svgtest)
project(${PROJECT_NAME})

add_subdirectory("googletest")
enable_testing()
include_directories(
    ${gtest_SOURCE_DIR}/include 
    ${gtest_SOURCE_DIR}

    ${xml_SOURCE_DIR}
    ${svgeditor_SOURCE_DIR}/src
    )

set_target_properties(gtest gtest_main gmock gmock_main PROPERTIES FOLDER GTest)

# Now simply link against gtest or gtest_main as needed. Eg
add_executable(xml_test "src/xml_test.cpp")
target_link_libraries(xml_test
    gtest_main
    xml
    )

add_executable(svg_test
    "src/svgcanvas_test.cpp"
    "src/svgreader_test.cpp"
    "src/svgwriter_test.cpp"
    )

target_link_libraries(svg_test
    gtest_main
    svgeditor
    )

add_test(NAME xml_test COMMAND xml_test)
add_test(NAME svg_test COMMAND svg_test)

set_target_properties(xml_test svg_test PROPERTIES FOLDER "Unit Test")

set(BINARY_NAME svg_test)
find_package(Qt5 COMPONENTS Core)
if (RUN_WINDEPLOYQT)
	# 自动运行 windeployqt
	# 参考: https://riptutorial.com/qt/example/24133/integrating-with-cmake
	get_target_property(_qmake_executable Qt5::qmake IMPORTED_LOCATION)
	get_filename_component(_qt_bin_dir "${_qmake_executable}" DIRECTORY)
	find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}")
	add_custom_command(TARGET ${BINARY_NAME} POST_BUILD
		COMMAND "${CMAKE_COMMAND}" -E
			env PATH="${_qt_bin_dir}" "${WINDEPLOYQT_EXECUTABLE}"
				"$<TARGET_FILE:${BINARY_NAME}>"
		COMMENT "Running windeployqt..."
	)
endif()


